package com.skivingcloud.report.constants;

/**
 * @author hushouquan
 * @since 2024/6/3
 */
public class ReportConstant {
    public static final String REPORT_BASE_URL = "/report";
    /**
     * 通用是否 是
     */
    public static final String COMMON_YES_OR_NO_YES = "1";
    /**
     * 通用是否 否
     */
    public static final String COMMON_YES_OR_NO_NO = "0";

    /**
     * 启用
     */
    public static final String REPORT_ENABLE_FLAG_E = "1";
    /**
     * 禁用
     */
    public static final String REPORT_ENABLE_FLAG_D = "0";

    public enum SetTypeEnum{
        SQL("sql", "sql"),
        HTTP("http", "http"),
        ;

        private final String codeValue;
        private final String codeDesc;

        SetTypeEnum(String codeValue, String codeDesc) {
            this.codeValue = codeValue;
            this.codeDesc = codeDesc;
        }

        public String getCodeValue() {
            return this.codeValue;
        }

        public String getCodeDesc() {
            return this.codeDesc;
        }

        //根据codeValue获取枚举
        public static SetTypeEnum parseFromCodeValue(String codeValue) {
            for (SetTypeEnum e : SetTypeEnum.values()) {
                if (e.codeValue.equals(codeValue)) {
                    return e;
                }
            }
            return null;
        }

        //根据codeValue获取描述
        public static String getCodeDescByCodeBalue(String codeValue) {
            SetTypeEnum enumItem = parseFromCodeValue(codeValue);
            return enumItem == null ? "" : enumItem.getCodeDesc();
        }

        //验证codeValue是否有效
        public static boolean validateCodeValue(String codeValue) {
            return parseFromCodeValue(codeValue) != null;
        }

        //列出所有值字符串
        public static String getString() {
            StringBuilder buffer = new StringBuilder();
            for (SetTypeEnum e : SetTypeEnum.values()) {
                buffer.append(e.codeValue).append("--").append(e.getCodeDesc()).append(", ");
            }
            buffer.deleteCharAt(buffer.lastIndexOf(","));
            return buffer.toString().trim();
        }
    }
}
